package com.miracle.login.module.mvp.presenter;

import android.app.Activity;
import android.util.Log;

import com.miracle.basemvp.base.BasePresenter;
import com.miracle.basemvp.base.BaseResponse;
import com.miracle.basemvp.base.IPresenter;
import com.miracle.basemvp.lifecycle.rx.RxDefaultObserver;
import com.miracle.login.module.mvp.contract.RegisterContract;
import com.miracle.login.module.mvp.entity.request.RegisterRequest;
import com.trello.rxlifecycle2.LifecycleProvider;
import com.trello.rxlifecycle2.android.ActivityEvent;

import javax.inject.Inject;

/**
 * com.miracle.login.module.mvp.presenter
 * (c)2018 AIR Times Inc. All rights reserved.
 *
 *
 * @author WangJQ
 * @version 1.0
 * @date 2018/7/5 14:19
 * @see com.miracle.login.module.mvp.presenter
 */
public class RegisterPresenter extends BasePresenter<RegisterContract.View, RegisterContract
        .Model> implements IPresenter {

    @Inject
    public RegisterPresenter(RegisterContract.View view, RegisterContract.Model model) {
        super(view, model);
    }

    public void register(LifecycleProvider<ActivityEvent> lifecycleProvider, RegisterRequest
            request) {
        request.setUri("register");
        mModel.register(request)
                .compose(lifecycleProvider.<BaseResponse<String>>bindUntilEvent
                        (ActivityEvent.DESTROY))
                .subscribe(new RxDefaultObserver<BaseResponse<String>>((Activity)
                        mView) {
                    @Override
                    public void onSucceed(BaseResponse<String> response) {
                        mView.registerSucc();
                    }

                    @Override
                    public void onNext(BaseResponse<String> stringBaseResponse) {
                        super.onNext(stringBaseResponse);
                        Log.d("WJQ", "onNext");
                    }
                });
    }
}
